#include "PrecompiledHeader.h"
#include "Sound.h"

/*--------------------------------------------------------------------------*/

Sound::Sound(const std::string& filename) :
	IResource("sound:" + filename)
{
	this->m_path = filename;
	this->m_chunk = NULL;
}

/*--------------------------------------------------------------------------*/

Sound::~Sound()
{
	if (this->m_chunk != NULL)
	{
		Mix_FreeChunk(this->m_chunk);
		this->m_chunk = NULL;
	}
}

/*--------------------------------------------------------------------------*/

Mix_Chunk* Sound::GetChunk() const
{
	return this->m_chunk;
}

/*--------------------------------------------------------------------------*/

void Sound::Reload()
{
	if (this->m_chunk != NULL)
	{
		Mix_FreeChunk(this->m_chunk);
		this->m_chunk = NULL;
	}

	this->m_chunk = Mix_LoadWAV(this->GetPath().c_str());

	AssertLogE(this->m_chunk == NULL, "Can not load file: %s", this->m_path);
}

/*--------------------------------------------------------------------------*/

const std::string& Sound::GetPath() const
{
	return this->m_path;
}

/*--------------------------------------------------------------------------*/

void Sound::SetPath(const std::string& path)
{
	this->m_path = path;
}

/*--------------------------------------------------------------------------*/